package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetMealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : [chenxys]
 * @version : [v1.0]
 * @Description : 套餐列表管理
 * @createTime : [2022/5/25 13:14]
 */
@RestController
@RequestMapping(value = "/setMeal")
public class SetMealController {

    @Reference
    private SetMealService setMealService;

    /**
     * 查询所有套餐
     * @author chenxys
     * @return com.itheima.entity.Result
     */
    @RequestMapping(value = "/getSetMeal")
    public Result getSetMeal(){
        try {
            List<Setmeal> setmealList = setMealService.findAll();
            return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS,setmealList);
        }catch (Exception e){
            return new Result(false,MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
    }

    /**
     * 根据ID查询对应的套餐信息
     * @author chenxys
     * @param id 套餐ID
     * @return com.itheima.entity.Result
     */
    @RequestMapping(value = "/findById")
    public Result findById(Integer id){
        try {
            Setmeal setmeal = setMealService.findByIds(id);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        }catch (Exception e){
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
